## This is R code for "The Demand for Insurance: Incorporating the Severity of
## Losing Office into the Insurance Model of Judicial Independence"
## Robustness check
## Rolling window previous 10 years
## And: cumulative sum of punishment 
## where the punishments of imprisonment and exile have lower weights
## see Data.Prep.R for the respective weights

rm(list = ls())
## install.packages("pacman") #load all packages
## remotes::install_github("chrisadolph/simcf") since simcf cannot be directly installed
pacman::p_load(
  tidyverse,this.path,texreg,MASS,AER,ivregEX,ivpack,simcf,arm,stargazer,ivmodel
)
## set working directory
setwd(this.path::here(..=1))
## read data
load("Data/dat.RData")

## Preparation -----------------------------------------------------------------
## a. Select the threats variables
dat <- dat %>%
  mutate(
    threat = threat_roll10_wt_low,
    threatS = threatS_roll10_wt_low
  )

## b. Specify the directories for table and figure
robustness_dir <- "./RobustnessCheck/roll10_wt_low/"
dir.create(robustness_dir, showWarnings = FALSE)
dir_table <- paste0(robustness_dir, "maintable.tex")
dir_figure <- paste0(robustness_dir, "plot_me.pdf") 

## Run everything --------------------------------------------------------------
source("Code/EstimationTableFigure.R")

## double check figure
plot_me

ggsave(plot_me, file=dir_figure)
